home *** CD-ROM | disk | FTP | other *** search
- Path: rcp6.elan.af.mil!rscernix!danpop
- From: danpop@mail.cern.ch (Dan Pop)
- Newsgroups: comp.lang.c
- Subject: Re: memory allocation using malloc and free
- Date: 19 Feb 96 22:13:00 GMT
- Organization: CERN European Lab for Particle Physics
- Message-ID: <danpop.824767980@rscernix>
- References: <4gagll$5rc@bertrand.ccs.carleton.ca>
- NNTP-Posting-Host: ues5.cern.ch
- X-Newsreader: NN version 6.5.0 #7 (NOV)
-
- In <4gagll$5rc@bertrand.ccs.carleton.ca> tcope@chat.carleton.ca (Tyler Cope) writes:
-
- >Could someone please demonstrate the proper (or _a_ proper) ANSI
- >method of allocating >64K space using malloc and free. I've tried many
- >versions and most work when malloc() and free() are both called from
- >main(), but when a separate function is called, everything goes crazy.
-
- There is no proper way to use malloc to allocate more bytes than can
- be stored in a size_t variable, for the simple reason that the prototype
- of malloc is:
-
- void *malloc(size_t size);
-
- If size_t is a 16-bit unsigned integer type on your platform, 64k is a
- hard limit for malloc.
-
- An apparent workaround would be to use calloc instead, because it has
- two size_t arguments. In practice, calloc is not able to allocate more
- bytes than malloc, however.
-
- If size_t is larger than 16 bits, the restrictions on the maximum memory
- block that can be allocated using malloc are usually imposed by external
- factors (e.g. the amount of physical or virtual memory available to the
- program when malloc was called).
-
- The usual workaround on unextended MSDOS is to use vendor-specific
- functions which take long or unsigned long arguments. Of course, this
- has nothing to do with ANSI C any longer.
-
- Dan
- --
- Dan Pop
- CERN, CN Division
- Email: danpop@mail.cern.ch
- Mail: CERN - PPE, Bat. 31 R-004, CH-1211 Geneve 23, Switzerland
-